1 using UnityEngine;
2 using
System.Collections;
3
4 public
class Brick : MonoBehaviour
5 {
6
7
8     
void OnCollisionEnter2D(Collision2D col)
9     {
10         
if (col.gameObject.GetComponent<Rigidbody2D>() == null) return;
11
12         
float damage = col.gameObject.GetComponent<Rigidbody2D>().velocity.magnitude * 10;
13         
//don't play audio for small damages
14         
if (damage >= 10)
15             GetComponent<AudioSource>().Play();
16         
//decrease health according to magnitude of the object that hit us
17         Health -= damage;
18         
//if health is 0, destroy the block
19         
if (Health <= 0) Destroy(this.gameObject);
20     }
21
22     
public float Health = 70f;
23
24
25     
//wood sound found in
26     
//https://www.freesound.org/people/Srehpog/sounds/31623/
27 }



Trò chơi Angry Birds trong UNITY Engine 31.694 lượt xem

Gõ tìm kiếm nhanh...